// JavaScript source code
XRMQuickFormHelper = function () {
    var openQuickCreate = function (entityLogicalName, createFromEntity, parameters) {
        var deferred = jQueryApi.jQueryDeferredFactory.Deferred(Xrm.SaveSuccessResponse, Xrm.SaveErrorResponse);
        var sucess = function (p1) {
            deferred.resolve(p1);
        };
        var error = function (p1) {
            deferred.reject(p1);
        };
        xrmLaunchGlobalQuickCreate(sucess, error, entityLogicalName, createFromEntity, parameters);
    };

    var xrmLaunchGlobalQuickCreate = function (successCallback, errorCallback, entityLogicalName, createFromEntity, extraParameters) {
        var callbacks = new Mscrm.GlobalQuickCreate.GlobalQuickCreateCallbacks("NavBarGloablQuickCreate", 990);
        callbacks.$O_1 = successCallback;
        callbacks.$N_1 = errorCallback;

        var fromEntityId = null
        var fromEntityType = -1;

        if (!IsNull(createFromEntity)) {
            fromEntityId = createFromEntity.id;
            fromEntityType = Xrm.Internal.getEntityCode(createFromEntity.entityType);
        }
        var entityCode = Xrm.Internal.getEntityCode(entityLogicalName)
        var entityDisplayName = ""; //entityLogicalName; //Should be display name
        Mscrm.GlobalQuickCreate.GlobalQuickCreateBehavior.launchGlobalQuickCreate(callbacks, entityDisplayName, entityCode, null, fromEntityId, fromEntityType, null, null, null, extraParameters);
    };

    return {
        openQuickCreate: openQuickCreate
    }
}();